﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;

namespace WindowsServerManage
{
    partial class MainService : ServiceBase
    {
        private readonly IScheduler scheduler;
        public MainService()
        {
            InitializeComponent();
            scheduler = TaskAsync().Result;
        }

        protected override void OnStart(string[] args)
        {
            scheduler.Start();
            // LogHelp.SysLog("Quartz服务成功启动----", "MyFirstQuartzService");
        }
        protected override void OnStop()
        {

            // 在此处添加代码以执行停止服务所需的关闭操作。
            scheduler.Shutdown();
            //   LogHelp.SysLog("Quartz服务成功终止", "MyFirstQuartzService");
        }
        //protected override void OnPause()
        //{
        //    scheduler.PauseAll();
        //}
        //protected override void OnContinue()
        //{
        //    scheduler.ResumeAll();
        //}



        public async Task<IScheduler> TaskAsync()
        {
            // 从工厂中获取调度程序实例
            var props = new NameValueCollection
                {
                    { "quartz.serializer.type", "binary" }
                };
            var factory = new StdSchedulerFactory(props);
            return await factory.GetScheduler();
        }

    }
}
